<%--
  Created by IntelliJ IDEA.
  User: zjk
  Date: 2018-08-02
  Time: 14:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>合同/订单视图</title>

    <link rel="shortcut icon" href="/easyui/css/images/favicon.ico"/>
    <link rel="stylesheet" href="/css/flipclock.css">
    <link href="/css/CalcSS3.css" rel="stylesheet" type="text/css"/>
    <link href="/css/index.css" rel="stylesheet" type="text/css"/>
    <link href="/easyui/css/easyui.css" rel="stylesheet" type="text/css">
    <link href="/easyui/css/easyui_animation.css" rel="stylesheet" type="text/css">
    <link href="/easyui/css/easyui_plus.css" rel="stylesheet" type="text/css">
    <link href="/easyui/css/insdep_theme_default.css" rel="stylesheet" type="text/css">
    <link href="/easyui/css/icon.css" rel="stylesheet" type="text/css">
    <link href="/easyui/css/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <!-- 引入 自身样式-->
    <link href="/css/utils/utilsDetails.css" rel="stylesheet" type="text/css">
    <!-- 引入 ECharts 文件 -->
    <script src="/js/echarts.js"></script>
    <!--放入自定义的图表-->
    <script src="/js/monitor.js"></script>
    <script type="text/javascript" src="/easyui/js/jquery.min.js"></script>
    <script type="text/javascript" src="/easyui/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/easyui/js/jquery.insdep-extend.min.js"></script>
</head>
<body>
<%--合同/订单的显示--%>
<table class="utils-table" border="0">
    <tr>
        <td colspan="4" style="text-align: center;"><span class="line-sp">----------------<span
                class="title-sp">合同/订单</span>----------------</span></td>
    </tr>
    <tr>
        <td>主题：</td>
        <td class="content-td" style="text-align: left;"><input readonly="readonly"
                                                                value="${contractVo.contract.contractTopic}"/>
        </td>
        <td>对应客户：</td>
        <td class="content-td" style="text-align: left;"><input readonly="readonly"
                                                                value="${contractVo.cname}"/></td>
    </tr>
    <tr>
        <td>对应机会：</td>
        <td class="content-td" style="text-align: left;"><input readonly="readonly"
                                                                value="${contractVo.planName}"/></td>
        <td>总金额：</td>
        <td class="content-td" style="text-align: left;"><input readonly="readonly"
                                                                value="${contractVo.contract.contractMoney}"/>
        </td>
    </tr>
    <tr>
        <td>发货金额：</td>
        <td class="content-td" style="text-align: left;"><input readonly="readonly" value="0"/></td>
        <td>回款金额：</td>
        <td class="content-td" style="text-align: left;"><input readonly="readonly"
                                                                value="${contractVo.contract.orderBackMoney}"/>
        </td>
    </tr>
    <tr>
        <td>日期：</td>
        <td class="content-td" style="text-align: left;"><input readonly="readonly"
                                                                value="${contractVo.contract.orderStartTime}"/>
        </td>
        <td>最晚日期：</td>
        <td class="content-td" style="text-align: left;"><input readonly="readonly"
                                                                value="${contractVo.contract.orderOverTime}"/>
        </td>
    </tr>
    <tr>
        <td>客户联系人：</td>
        <td class="content-td" style="text-align: left;"><input id="dr5hx-contractAlldetails-contact"
                                                                readonly="readonly"
                                                                value=""/>
        </td>
    </tr>
    <tr>
        <td>退货：</td>
        <td class="content-td" style="text-align: left;"><input readonly="readonly"
                                                                value="${contractVo.contract.contractIsRefund}"/>
        </td>
        <td>所有者：</td>
        <td class="content-td" style="text-align: left;"><input readonly="readonly"
                                                                value="${contractVo.eName}"/></td>
    </tr>
    </tr>
    <tr>
        <td>状态：</td>
        <td class="content-td" style="text-align: left;"><input readonly="readonly"
                                                                value="${contractVo.contract.contractState}"/>
        </td>
        <td>收货地址：</td>
        <td class="content-td" style="text-align: left;"><input readonly="readonly"
                                                                value="${contractVo.contract.contractAddress}"/>
        </td>
    </tr>
    <tr>
        <td>备注：</td>
        <td colspan="3" style="text-align: left;">
                    <textarea readonly="readonly" rows="5" cols="80"
                              style="border: 1px; background-color: #E6EEF8; ">${contractVo.contract.contractRemark}</textarea>
        </td>
    </tr>
    <tr>
        <td colspan="4" style="text-align: center;"><span class="line-sp">----------------<span
                class="title-sp">合同/订单详情</span>----------------</span></td>
    </tr>
</table>
<div style=" position: absolute; left: 50%;transform: translate(-50%,0);">
    <%--商品细节显示--%>
    <table align="center" id="dr5hx-contract-load-edit-codetails"
           data-options="align:'center',width:'1180', toolbar:'#dr5hx-contract-load-edit-codetails-toolsbar'"
           class="easyui-datagrid"
           style="height:auto">
        <thead>
        <tr class="datagrid-header-row">
            <th data-options="field:'productName',width:200,align:'center',formatter: function (value, row, index) {
                                                                return row.productionDetail.pname;}">品名
            </th>
            <th data-options="field:'productionNumber',width:80,align:'center',
                    formatter:function(value,row,index){
                    return row.productionDetail.pid;}">编号
            </th>
            <th data-options="field:'productionUnit',width:80,align:'center',
                    formatter: function (value, row, index) {return row.productionDetail.pwunit; }">
                单位
            </th>
            <th data-options="field:'productAccount',width:80,align:'center',formatter: function (value, row, index) {
                    return row.coDetail.cOAmount;
                    }">数量
            </th>
            <th data-options="field:'productCompleteAccount',width:80,align:'center',
                    formatter: function (value, row, index) {
                    return row.coDetail.cOCompleteAccount;
                    }">已交付
            </th>
            <th data-options="field:'productPrice',width:80,align:'center', formatter: function (value, row, index) {
                    return row.coDetail.cOPrice;
                    }">单价
            </th>
            <th data-options="field:'productioMoney', width:80,align:'center',
                    formatter: function (value, row, index) {
                    return row.coDetail.cOMoney;
                    }">总金额
            </th>
            <th data-options="field:'cOTime', width:100,align:'center',
                    formatter: function (value, row, index) {
                    return row.coDetail.cOTime;
                    }">预计发货时间
            </th>
            <th data-options="field:'productRemark',width:200,align:'center',formatter: function (value, row, index) {
                    return row.coDetail.cORemark;
                    }">备注
            </th>
        </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
    <br/>
    <div>
            <span class="line-sp"
                  style=" position: absolute ; left: 50%;transform: translate(-50%,0)">----------------<span
                    class="title-sp">发货单</span>----------------</span>
    </div>
    <br/>
    <br/>
    <div style=" position: absolute; left: 50%;transform: translate(-50%,0);">
        <%--发货单的显示table--%>
        <table align="center" id="dr5hx-contractAllDetails_dispatcher"
               data-options="align:'center',width:'1160', toolbar:'#dr5hx-contractAllDetails_dispatcher_buttons'"
               class="easyui-datagrid"
               style="height:auto">
            <thead>
            <tr class="datagrid-header-row">
                <th data-options="field:'productName',width:200,align:'center',formatter:
                function (value, row, index) {return row.productionDetail.pname; }">
                    品名
                </th>
                <th data-options="field:'productionNumber',width:80,align:'center',formatter:
                function (value, row, index) {return row.productionDetail.pid; }">编号
                </th>
                <th data-options="field:'productionUnit',width:80,align:'center',formatter:
                function (value, row, index) {return row.productionDetail.pwunit; }">
                    单位
                </th>
                <th data-options="field:'productAccount',width:80,align:'center',formatter:
                function (value, row, index) {return row.dispatcherDetail.productAccount; }">数量
                </th>
                <th data-options="field:'productPrice',width:80,align:'center',formatter:
                function (value, row, index) {return row.coDetail.cOPrice; }">单价
                </th>
                <th data-options="field:'productioMoney', width:80,align:'center',formatter:
                function (value, row, index) {return row.coDetail.cOPrice*row.dispatcherDetail.productAccount; }">总金额
                </th>
                <th data-options="field:'checkState', width:100,align:'center',formatter:
                function (value, row, index) {
                if(row.dispatcherDetail.fkDispatcherId==0){
                 return '未审核';
                 }else if(row.dispatcherDetail.fkDispatcherId==1){
                   return '发货中';
                 }else if(row.dispatcherDetail.fkDispatcherId==2){
                  return '完成';
                 }else if(row.dispatcherDetail.fkDispatcherId==3){
                 return '部分退货';
                 }else if(row.dispatcherDetail.fkDispatcherId==4){
                   return '全部退货';
                 }else{
                 return '未知错误';
                 }
             }
              ">状态
                </th>
                <th data-options="field:'productRemark',width:200,align:'center',formatter:
                function (value, row, index) {return row.coDetail.cORemark; }">备注
                </th>
                <th data-options="field:'dispatcherTime',width:200,align:'center',formatter:
                function (value, row, index) {return row.dispatcherDetail.dispatcher.fkDispatcherCustomer; }">发货单生成时间
                </th>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
        <%--发货单的table的添加和退货按钮--%>
        <div id="dr5hx-contractAllDetails_dispatcher_buttons">
            <a id="dr5hx-contractAllDetails_dispatcher_buttons-add" class="easyui-linkbutton" plain="true"
               iconCls="icon-mini_add2">添加</a>
            <a id="dr5hx-contractAllDetails_dispatcher_buttons-edit"
               class="easyui-linkbutton" plain="true"
               iconCls="icon-my_edit">退货</a>
        </div>
        <%--显示出库单的详情dialog--%>
        <div id="dr5hx-contractAllDetails_dispatcher-dialog"
             class="easyui-dialog" style="background-color:#EBEFF2;" data-options="iconCls:'icon-save2',
			width:1090,
			height:'auto',
			closed:true,
			bodyCls:'by',
			shadow:true,
			title:'添加出库单及详情',
			modal:true,
			buttons:'#dr5hx-contractAllDetails_dispatcher-dialog-button'">
            <form method="post" id="dr5hx-contractAllDetails_dispatcher-dialog-form">
                <input type="hidden" id="dr5hx-contractAllDetails_dispatcher-dialog-form-contractId" name="contractId"/>
                <input id="dr5hx-contractAllDetails_dispatcher-dialog-form-input" name="iotitle" class="easyui-textbox"
                       data-options="label:'出库单名称',width:300"/>
                <input name="empno" id="dr5hx-contractAllDetails_dispatcher-dialog-form-combobox"
                       class="easyui-combobox" data-options="width:300,label:'经手人'">
                <table align="center" id="dr5hx-contractAllDetails_dispatcher-dialog-table"
                       data-options="align:'center',
                       width:'1085', toolbar:'#dr5hx-contractAllDetails_dispatcher-dialog-table-buttons',
                        singleSelect:true"
                       class="easyui-datagrid"
                       style="min-height:100px">
                    <thead>
                    <tr class="datagrid-header-row">
                        <th data-options="field:'productName',width:200,align:'center',formatter: function (value, row, index) {
                                                                return row.productionDetail.pname;}">品名
                        </th>
                        <th data-options="field:'productionNumber',width:80,align:'center',formatter:function(value,row,index){
                                                                 return row.productionDetail.pid;}">型号
                        </th>
                        <th data-options="field:'productionUnit',width:80,align:'center',formatter:function(value,row,index){
                                                                return row.productionDetail.pwunit;}">
                            单位
                        </th>
                        <th name="productAmount" data-options="field:'productAccount',width:80,align:'center',formatter:function( value,row,index){
                                                                return row.coDetail.cOAmount-row.coDetail.cOCompleteAccount-row.coDetail.fkOrderId-row.coDetail.productType}
               ">
                            数量
                        </th>
                        <th data-options="field:'productPrice',width:80,align:'center',formatter:function(value,row,index){
                                                                return row.coDetail.cOPrice;}">单价
                        </th>
                        <th data-options="field:'productioMoney', width:80,align:'center',formatter:function(value,row,index){
                                                                return row.coDetail.cOPrice*(row.coDetail.cOAmount-row.coDetail.cOCompleteAccount-row.coDetail.fkOrderId-row.coDetail.productType);}">
                            总金额
                        </th>
                        <th data-options="field:'productRemark',width:300,align:'center',formatter:function(value,row,index){
                                                                return row.coDetail.cORemark;}">备注
                        </th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </form>
            <%--查看可出库的商品dialog的修改删除键--%>
            <div id="dr5hx-contractAllDetails_dispatcher-dialog-table-buttons">
                <a id="dr5hx-contractAllDetails_dispatcher-dialog-table-buttons-edit"
                   class="easyui-linkbutton" plain="true"
                   iconCls="icon-my_edit">修改</a>
                <a id="dr5hx-contractAllDetails_dispatcher-dialog-table-buttons-delete" class="easyui-linkbutton"
                   plain="true"
                   iconCls="icon-my_delete">删除</a>
            </div>
        </div>
        <%--退货dialog--%>
        <div id="dr5hx-contractAllDetails_dispatcher-refund_dialog" class="easyui-dialog"
             data-options="closed:true,
            bodyCls:'by',
            shadow:true,
            modal:true,
            width:840,
			height:'auto',
			title:'退货',
			buttons:'#dr5hx-contractAllDetails_dispatcher-refund_dialog-button'
            ">
            <form method="post" id="dr5hx-contractAllDetails_dispatcher-refund_dialog-form">
                <input type="hidden" id="dr5hx-contractAllDetails_dispatcher-refund_dialog-form-contractId"
                       name="contractId"/>
                <input id="dr5hx-contractAllDetails_dispatcher-refund_dialog-form-input" name="refundTitle"
                       class="easyui-textbox"
                       data-options="label:'退货主题',width:300"/>
                <input name="empno" id="dr5hx-contractAllDetails_dispatcher-refund_dialog-form-combobox"
                       class="easyui-combobox" data-options="width:300,label:'经手人'">
                <table align="center" id="dr5hx-contractAllDetails_dispatcher-refund_dialog-table"
                       data-options="align:'center',
                       width:'835', toolbar:'#dr5hx-contractAllDetails_dispatcher-refund_dialog-table-buttons',
                        singleSelect:true,scrollbarSize:0"
                       class="easyui-datagrid"
                       style="min-height:100px">
                    <thead>
                    <tr class="datagrid-header-row">
                        <th data-options="field:'productName',width:200,align:'center',formatter: function (value, row, index) {
                                                                return row.productionDetail.pname;}">品名
                        </th>
                        <th data-options="field:'productionNumber',width:100,align:'center',formatter:function(value,row,index){
                                                                 return row.productionDetail.pid;}">型号
                        </th>
                        <th data-options="field:'productionUnit',width:100,align:'center',formatter:function(value,row,index){
                                                                return row.productionDetail.pwunit;}">
                            单位
                        </th>
                        <th name="productAmount" data-options="field:'productAccount',width:100,align:'center',formatter:function( value,row,index){

                                                                return row.coDetail.cOCompleteAccount;}
               ">
                            数量
                        </th>
                        <th data-options="field:'productPrice',width:100,align:'center',formatter:function(value,row,index){
                                                                return row.coDetail.cOPrice;}">单价
                        </th>
                        <th data-options="field:'productioMoney', width:100,align:'center',formatter:function(value,row,index){
                                                                return row.coDetail.cOPrice*row.coDetail.cOCompleteAccount}">
                            总金额
                        </th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </form>
            <div id="dr5hx-contractAllDetails_dispatcher-refund_dialog-table-buttons">
                <a id="dr5hx-contractAllDetails_dispatcher-refund_dialog-table-buttons-edit"
                   class="easyui-linkbutton" plain="true"
                   iconCls="icon-my_edit">修改</a>
                <a id="dr5hx-contractAllDetails_dispatcher-refund_dialog-table-buttons-delete" class="easyui-linkbutton"
                   plain="true"
                   iconCls="icon-my_delete">删除</a>
            </div>
        </div>
        <%--退货关闭保存按钮--%>
        <div id="dr5hx-contractAllDetails_dispatcher-refund_dialog-button">
            <a href="#" id="dr5hx-contractAllDetails_dispatcher-refund_dialog-button-save"
               class="easyui-linkbutton"
               data-options="iconCls:'icon-ok2'">保存</a>
            <a href="#" id="dr5hx-contractAllDetails_dispatcher-refund_dialog-close"
               class="easyui-linkbutton"
               data-options="iconCls:'icon-cancel2',
    onClick:function(){
        $('#dr5hx-contractAllDetails_dispatcher-refund_dialog').window('close');
        $('#dr5hx-contractAllDetails_dispatcher-refund_dialog-form-input').textbox({
        value:''})
        $('#dr5hx-contractAllDetails_dispatcher-refund_dialog-form-combobox').combobox({
         value:''
        })
        $('#dr5hx-contractAllDetails_dispatcher-refund_dialog-table').datagrid('reload')

    }">关闭</a>
        </div>
        <%--退货修改数量dialog--%>
        <div id="dr5hx-contractAllDetails_dispatcher-refund_dialog-table-buttons-edit-dialog" class="easyui-dialog"
             data-options="closed:true,
            bodyCls:'by',
            shadow:true,
            modal:true,
            width:400,
			height:'150',
			title:'修改退货数量',
			buttons:'#dr5hx-contractAllDetails_dispatcher-refund_dialog-table-buttons-edit-dialog-button'
            ">
            <input id="dr5hx-contractAllDetails_dispatcher-refund_dialog-table-buttons-edit-dialog-textbox"
                   class="easyui-textbox" data-options="label:'退货数量', width:200">
        </div>
        <%--退货修改dialog的保存按钮--%>
        <div id="dr5hx-contractAllDetails_dispatcher-refund_dialog-table-buttons-edit-dialog-button">
            <a href="#" id="dr5hx-contractAllDetails_dispatcher-refund_dialog-table-buttons-edit-dialog-button-save"
               class="easyui-linkbutton"
               data-options="iconCls:'icon-ok2'">保存</a>
            <a href="#" id="dr5hx-contractAllDetails_dispatcher-refund_dialog-table-buttons-edit-dialog-button-close"
               class="easyui-linkbutton"
               data-options="iconCls:'icon-cancel2',
    onClick:function(){
        $('#dr5hx-contractAllDetails_dispatcher-refund_dialog-table-buttons-edit-dialog').window('close');
    }">关闭</a>
        </div>
        <%--修改出库数量dialog--%>
        <div id="dr5hx-contractAllDetails_dispatcher-dialog-table-buttons-edit-dialog" class="easyui-dialog"
             data-options="closed:true,
            bodyCls:'by',
            shadow:true,
            modal:true,
            width:400,
			height:'150',
			title:'修改出库数量',
			buttons:'#dr5hx-contractAllDetails_dispatcher-dialog-table-buttons-edit-dialog-button'
            ">
            <input id="dr5hx-contractAllDetails_dispatcher-dialog-table-buttons-edit-dialog-textbox"
                   class="easyui-textbox" data-options="label:'出库数量', width:200">
        </div>
        <%--修改出库数量dialog保存关闭按钮--%>
        <div id="dr5hx-contractAllDetails_dispatcher-dialog-table-buttons-edit-dialog-button">
            <a href="#" id="dr5hx-contractAllDetails_dispatcher-dialog-table-buttons-edit-dialog-button-save"
               class="easyui-linkbutton"
               data-options="iconCls:'icon-ok2'">保存</a>
            <a href="#" id="dr5hx-contractAllDetails_dispatcher-dialog-table-buttons-edit-dialog-button-close"
               class="easyui-linkbutton"
               data-options="iconCls:'icon-cancel2',
    onClick:function(){
        $('#dr5hx-contractAllDetails_dispatcher-dialog-table-buttons-edit-dialog').window('close');
    }">关闭</a>
        </div>
        <%--显示可发货详情dialog保存按钮--%>
        <div id="dr5hx-contractAllDetails_dispatcher-dialog-button">
            <a href="#" id="dr5hx-contractAllDetails_dispatcher-dialog-button-save" class="easyui-linkbutton"
               data-options="iconCls:'icon-ok2'">保存</a>
            <a href="#" id="dr5hx-contractAllDetails_dispatcher-dialog-button-close" class="easyui-linkbutton"
               data-options="iconCls:'icon-cancel2',
    onClick:function(){
        $('#dr5hx-contractAllDetails_dispatcher-dialog').window('close');
        $('#dr5hx-contractAllDetails_dispatcher-dialog-form-input').textbox({
        value:''})
        $('#dr5hx-contractAllDetails_dispatcher-dialog-form-combobox').combobox({
         value:''
        })
        $('#dr5hx-contractAllDetails_dispatcher-dialog-table').datagrid('reload');
    }">关闭</a>
        </div>
        <br/>
        <br/>
        <div>
            <span class="line-sp"
                  style=" position: absolute ; left: 25%;transform: translate(-50%,0)">----------------<span
                    class="title-sp">回款计划</span>----------------</span>
        </div>
        <div>
            <span class="line-sp"
                  style=" position: absolute ; left: 75%;transform: translate(-50%,0)">----------------<span
                    class="title-sp">回款记录</span>----------------</span>
        </div>
        <br/>
        <br/>
        <div style=" position: absolute; left: 25%;transform: translate(-50%,0)">
            <table align="center" id="dr5hx-contractAllDetails_planingback"
                   data-options="align:'center',
                       width:'614',
                        singleSelect:true,
                        url:'/getPlaningBackByContractId',
                        queryParams:{
                             contractId:${contractVo.contract.contractId}
                        }
                    "
                   class="easyui-datagrid"
                   style="min-height:100px">
                <thead>
                <tr class="datagrid-header-row">
                    <th data-options="field:'planingBackId',width:50,align:'center'">ID
                    </th>
                    <th data-options="field:'planingBackMoney',width:100,align:'center',formatter:function(row){
                        return '￥'+row

                    }">回款金额
                    </th>
                    <th data-options="field:'planingBackTime',width:100,align:'center'">预计回款时间
                    </th>
                    <th data-options="field:'planingBackIsBack',width:100,align:'center'">是否回款
                    </th>
                    <th data-options="field:'operate',width:'150',align:'center'" formatter="format">操作
                    </th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>

        <div style=" position: absolute;left:75%
                    ">


            <div style=" position: absolute; left: 75%;transform: translate(-50%,0);">
                <table align="center" id="dr5hx-contractAllDetails_back"
                       data-options="align:'center',
        width:'442',
        singleSelect:true, url:'/getBackRecordByContractId',
                        queryParams:{
                             contractId:${contractVo.contract.contractId}
                        }
                    "
                       class="easyui-datagrid"
                       style="min-height:100px">
                    <thead>
                    <tr class="datagrid-header-row">
                        <th data-options="field:'backId',width:50,align:'center'">ID
                        </th>
                        <th data-options="field:'backMoney',width:100,align:'center'">回款金额
                        </th>
                        <th data-options="field:'backTime',width:100,align:'center'">回款时间
                        </th>
                        <th data-options="field:'withdraw',width:100,align:'center'" formatter="format1">操作
                        </th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<script>
    <%--加载发货单详情--%>
    $("#dr5hx-contractAllDetails_dispatcher").datagrid({
        striped: true,
        fitColumns: true,
        autoRowHeight: true,
        nowrap: false,
        url: 'getDispatcherDetailListByContractId',
        queryParams: {
            contractId: ${contractVo.contract.contractId}
        },
        method: 'post',

    })

    //加载合同详情数据
    $("#dr5hx-contract-load-edit-codetails").datagrid({
        striped: true,
        fitColumns: true,
        autoRowHeight: true,
        nowrap: false,
        url: 'loadCODetailsList',
        queryParams: {
            contractId: ${contractVo.contract.contractId}
        },
        method: 'post',
    })
    //ajax设置用户值
    $(function () {
        var a = ${contractVo.contract.contractCustomer};
        $.post("findContactById", {id: a}, function (result) {
            $("#dr5hx-contractAlldetails-contact").val(result.contactName);
        });

    });
    //发货添加数据
    $("#dr5hx-contractAllDetails_dispatcher_buttons-add").linkbutton({
        onClick: function () {

            $("#dr5hx-contractAllDetails_dispatcher-dialog").window('open');
        }

    })

</script>

<script type="text/javascript">
    //删除不需要发货的产品
    $("#dr5hx-contractAllDetails_dispatcher-dialog-table").datagrid({
        url: 'loadDispatcherCODetailsList',
        queryParams: {
            contractId: ${contractVo.contract.contractId}
        },
        method: 'post'
    })

    $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-table").datagrid({
        striped: true,
        fitColumns: true,
        autoRowHeight: true,
        nowrap: false,
        url: 'loadRefundCODetailsList',
        queryParams: {
            contractId: ${contractVo.contract.contractId}
        },
        method: 'post',

    })


    //编辑发货详单
    $("#dr5hx-contractAllDetails_dispatcher-dialog-table-buttons-edit").linkbutton({
        onClick: function () {
            var a = $("#dr5hx-contractAllDetails_dispatcher-dialog-table").datagrid('getSelected');
            if (a) {
                $("#dr5hx-contractAllDetails_dispatcher-dialog-table-buttons-edit-dialog-textbox").textbox({
                    value: a.coDetail.cOAmount - a.coDetail.cOCompleteAccount - a.coDetail.fkOrderId,
                })
                $("#dr5hx-contractAllDetails_dispatcher-dialog-table-buttons-edit-dialog").window('open')
            } else {
                $.messager.alert("提示", "请选中一行")
            }
        }
    })
    //删除发货单
    $("#dr5hx-contractAllDetails_dispatcher-dialog-table-buttons-delete").linkbutton({
        onClick: function () {
            var a = $("#dr5hx-contractAllDetails_dispatcher-dialog-table").datagrid('getSelected');
            if (a) {
                var row = $("#dr5hx-contractAllDetails_dispatcher-dialog-table").datagrid('getSelected')
                var index = $("#dr5hx-contractAllDetails_dispatcher-dialog-table").datagrid('getRowIndex', row);
                $("#dr5hx-contractAllDetails_dispatcher-dialog-table").datagrid('deleteRow', index);
            } else {
                $.messager.alert("提示", "请选中一行")
            }
        }
    })
    $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-table-buttons-delete").linkbutton({
        onClick: function () {
            var a = $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-table").datagrid('getSelected');
            if (a) {
                var row = $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-table").datagrid('getSelected')
                var index = $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-table").datagrid('getRowIndex', row);
                $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-table").datagrid('deleteRow', index);
            } else {
                $.messager.alert("提示", "请选中一行")
            }
        }

    })
    //编辑退货单
    $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-table-buttons-edit").linkbutton({
        onClick: function () {
            var a = $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-table").datagrid('getSelected');
            if (a) {
                $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-table-buttons-edit-dialog-textbox").textbox({
                    value: a.coDetail.cOCompleteAccount,
                })
                $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-table-buttons-edit-dialog").window('open')
            } else {
                $.messager.alert("提示", "请选中一行")
            }

        }
    })
    //更新退货数据
    $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-table-buttons-edit-dialog-button-save").linkbutton({
        onClick: function () {
            var a = $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-table-buttons-edit-dialog-textbox").textbox('getValue')
            var row = $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-table").datagrid('getSelected');
            var index = $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-table").datagrid('getRowIndex', row);
            $.post("getALLNumberForRefund", {cOId: row.coDetail.cOId}, function (result) {
                if (a <= result && a > 0) {
                    $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-table").datagrid('updateRow', {
                        index: index,
                        row:
                            {
                                "coDetail":
                                    {
                                        cOId: row.coDetail.cOId,
                                        cOCompleteAccount: a,
                                        cOPrice: row.coDetail.cOPrice
                                    }
                            }
                    })
                    $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-table-buttons-edit-dialog").window('close')
                } else {
                    $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-table-buttons-edit-dialog").window('close')
                    $.messager.alert("提示", "不能超出数量")
                }
            })


        }
    })
    //编辑发货详情保存数据，并不提交
    $("#dr5hx-contractAllDetails_dispatcher-dialog-table-buttons-edit-dialog-button-save").linkbutton(
        {
            onClick: function () {
                var a = $("#dr5hx-contractAllDetails_dispatcher-dialog-table-buttons-edit-dialog-textbox").textbox('getValue')
                var row = $("#dr5hx-contractAllDetails_dispatcher-dialog-table").datagrid('getSelected')
                var index = $("#dr5hx-contractAllDetails_dispatcher-dialog-table").datagrid('getRowIndex', row);
                $.post("getNumberForDispatcher", {cOId: row.coDetail.cOId}, function (result) {
                    if (result - a >= 0 && a > 0) {
                        $("#dr5hx-contractAllDetails_dispatcher-dialog-table").datagrid('updateRow', {
                            index: index,
                            row:
                                {
                                    "coDetail":
                                        {
                                            cOId: row.coDetail.cOId,
                                            cOAmount: a,
                                            cOCompleteAccount: 0,
                                            cOPrice: row.coDetail.cOPrice,
                                            fkOrderId: 0,
                                            productType: 0

                                        }
                                }

                        })

                        $("#dr5hx-contractAllDetails_dispatcher-dialog-table-buttons-edit-dialog").window('close')
                    } else {
                        $("#dr5hx-contractAllDetails_dispatcher-dialog-table-buttons-edit-dialog").window('close')
                        $.messager.alert("提示", "数量error")
                    }
                })
            }
        }
    )
    //提交出库数据
    $("#dr5hx-contractAllDetails_dispatcher-dialog-button-save").linkbutton({
        onClick: function () {
            var rows = $("#dr5hx-contractAllDetails_dispatcher-dialog-table").datagrid("getRows");
            if (rows.length != 0) {
                $("#dr5hx-contractAllDetails_dispatcher-dialog-form").form({
                    url: "toAddOutboundOrder",
                    onSubmit: function (params) {
                        params.rows = JSON.stringify(rows)
                    },
                    success: function (data) {
                        var data = eval('(' + data + ')')
                        if (data.success == true) {
                            $.messager.alert("提示", "成功生成出库单，等待审核")
                            $("#dr5hx-contract-load-edit-codetails").datagrid('reload');
                            $("#dr5hx-contractAllDetails_dispatcher").datagrid('reload');
                            $('#dr5hx-contractAllDetails_dispatcher-dialog-form-input').textbox({
                                value: ''
                            })
                            $('#dr5hx-contractAllDetails_dispatcher-dialog-form-combobox').combobox({
                                value: ''
                            })
                            $('#dr5hx-contractAllDetails_dispatcher-dialog-table').datagrid('reload');
                            $("#dr5hx-contractAllDetails_dispatcher-dialog").window('close')
                        } else {
                            $.messager.alert("提示", data.message)
                            $("#dr5hx-contractAllDetails_dispatcher-dialog").window('close')
                        }
                    }
                })
                $('#dr5hx-contractAllDetails_dispatcher-dialog-form').submit();
            } else {
                $.messager.alert("提示", "数据为空,不予提交");
            }
        },

    })
    //提交退货
    $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-button-save").linkbutton({
        onClick: function () {
            var rows = $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-table").datagrid("getRows");
            if (rows.length != 0) {
                $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-form").form({
                    url: "toAddRefundOrderList",
                    onSubmit: function (params) {
                        params.rows = JSON.stringify(rows)
                    }, success: function (data) {
                        var data = eval('(' + data + ')')
                        if (data.success == true) {
                            $("#dr5hx-contractAllDetails_dispatcher-refund_dialog").dialog("close")
                            location.reload()
                        } else {

                            $.messager.alert("提示", data.message)
                            $("#dr5hx-contractAllDetails_dispatcher-dialog").window('close')
                            location.reload()
                        }
                    }

                })
                $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-form").submit()
            } else {
                $.messager.alert("提示", "数据为空,不予提交");
            }
        }
    })
    //赋值给隐藏域表单
    $("#dr5hx-contractAllDetails_dispatcher-dialog-form-contractId").val(${contractVo.contract.contractId})
    $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-form-contractId").val(${contractVo.contract.contractId})

    //请求员工列表
    $("#dr5hx-contractAllDetails_dispatcher-dialog-form-combobox").combobox({
        url: 'getUserInfoList',
        method: 'post',
        valueField: 'uId',
        textField: 'uname',
        label: "经手人",
        limitToList: true,
        panelHeight: 'auto'
    });
    $("#dr5hx-contractAllDetails_dispatcher-refund_dialog-form-combobox").combobox({
        url: 'getUserInfoList',
        method: 'post',
        valueField: 'uId',
        textField: 'uname',
        // label: "经手人",
        limitToList: true,
        panelHeight: 'auto'
    });
    //
    $("#dr5hx-contractAllDetails_dispatcher_buttons-edit").linkbutton({
        onClick: function () {
            $("#dr5hx-contractAllDetails_dispatcher-refund_dialog").window('open')
        }
    });

    //添加修改按钮


    function format(value, row, index) {
        var str = "<a name='change' class='easyui-linkbutton'>确认回款</a>";
        return str;
    }


    function format1(value, row, index) {
        var str = "<a name='withdraw' class='easyui-linkbutton'>撤销回款</a>";
        return str;
    }

    $(function () {
        //修改事件处理
        $("#dr5hx-contractAllDetails_planingback").datagrid({
            onLoadSuccess: function (data) {
                $("a[name='change']").linkbutton({
                    plain: true,
                    iconCls: 'icon-my_edit',
                    width: '100',
                    onClick: function () {
                        var rows = $('#dr5hx-contractAllDetails_planingback').datagrid('getRows');
                        $("#dr5hx-contractAllDetails_planingback").datagrid({
                            onClickCell: function (index) {
                                var planingBackId = rows[index].planingBackId;
                                $.post("/setPlaningBackMoneyAlreadyBack",
                                    {
                                        planingBackId: planingBackId,
                                        rows: JSON.stringify(rows[index])
                                    },
                                    function (data) {
                                        if (data == true) {
                                            $("#dr5hx-contractAllDetails_planingback").datagrid('reload')
                                            $("#dr5hx-contractAllDetails_back").datagrid("reload")
                                        } else {
                                            $.messager.alert("提示", "操作失败")
                                        }
                                    }
                                )


                                $('#dr5hx-contractAllDetails_planingback').datagrid({
                                    onClickCell: function (index) {
                                    }
                                });
                            }
                        });
                    }
                });

            }
        });
        $("#dr5hx-contractAllDetails_back").datagrid({
            onLoadSuccess: function (data) {
                $("a[name='withdraw']").linkbutton({
                    plain: true,
                    iconCls: 'icon-my_edit',
                    width: '100',
                    onClick: function () {
                        var rows = $('#dr5hx-contractAllDetails_back').datagrid('getRows');
                        $("#dr5hx-contractAllDetails_back").datagrid({
                            onClickCell: function (index) {
                                var backId = rows[index].backId;
                                $.post(
                                    "/withdrawBackRecord",
                                    {backId: backId},
                                    function (data) {
                                        if (data == true) {
                                            $("#dr5hx-contractAllDetails_planingback").datagrid('reload')
                                            $("#dr5hx-contractAllDetails_back").datagrid("reload")
                                        } else {
                                            $.messager.alert("提示", "操作失败")
                                        }
                                    }
                                )
                                $('#dr5hx-contractAllDetails_back').datagrid({
                                    onClickCell: function (index) {

                                    }
                                });
                            }
                        })
                    }

                })

            }
        })
    })
</script>
</body>
</html>